<?php
    $db = new Database();
    $fs = new Functions();
    $Campaign_Functions = new Campaign_Functions();
        $tb_campaign = $db->tbl_name(TB_CAMPAIGN);
                                                $tb_users = $db->tbl_name(TB_USERS);
                                                $tb_accounts = $db->tbl_name(TB_ACCOUNTS);
                                                $tb_brand_category = $db->tbl_name(TB_BRAND_CATEGORY);
                                                $tb_campaign_status = $db->tbl_name(TB_CAMPAIGN_STATUS);
                                    $query = $db->query("
                                                    SELECT *,c.id as campaign_id,cs.name as csName,cs.id as csID FROM $tb_campaign c 
                                                    LEFT JOIN $tb_users u ON c.user_id=u.id
                                                    LEFT JOIN $tb_accounts a ON u.account_id=a.id
                                                    LEFT JOIN $tb_campaign_status cs ON c.campaign_status_id=cs.id
                                                    WHERE c.campaign_status_id='2'
                                                    ","array");                        
?>
<div class="content">
    <!--- Bread Crumbs Menu -->
    <div class="breadLine">
        <ul class="breadcrumb">
            <li><a href="/">Admin</a> <span class="divider">></span></li>
            <li class="active"><a href="/">User</a> <span class="divider">></span></li>     
            <li class="active"><?php echo Config::get_page(); ?></li>
        </ul>
        <?php
            //echo $this->setLayout("breadcrumbs_right_menu");
        ?>
    </div>

   <div class="workplace">

        <div class="row-fluid">
            <div class="span12">
                <div class="head clearfix">
                    <div class="isw-calendar"></div>
                        <h1><?php echo Config::get_page(); ?></h1>
                    </div>
                    
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="widget">
                                <div class="head dark">
                                    <div class="icon title_icon"><i class="fa fa-list"></i></div>
                                    <h2>View Chart</h2>
                                </div>                        
                                <div class="block-fluid">
                                    <div class="tabs" style="overflow:auto;">                    
                                        <ul>
                                            <li class="br_s_tab"><a href="#q-1">Q1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                                            <li class="br_s_tab"><a href="#q-2">Q2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                                            <li class="br_s_tab"><a href="#q-3">Q3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                                            <li class="br_s_tab"><a href="#q-4">Q4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                                            <li class="br_s_tab"><a href="#view-all">View All&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                                        </ul>                        
                
                                            <div id="q-1">
                                                <?php
                                                        $sql = "SELECT * FROM " . $db->tbl_name(TB_CAMPAIGN_VERSION) .
                                                        " WHERE quarter = {$db->escape('q1')} ORDER BY campaign_id DESC";
                                                        $campaign_version_query = $db->query($sql,"array");
                                                        $campaign_version_query_nums = $db->query($sql,"numrows");
                                                        if($campaign_version_query_nums == 0){
                                                            echo '<p><strong><center>No Records Found.</center></strong></p>';
                                                        }
                                                    ?>
                                                <div class="accordion" style="overflow:auto">    
                                                    <?php
                                                        foreach($campaign_version_query as $data){
                                                    ?>
                                                        <h3><?php echo $data['version_name']; ?></h3>
                                                        
                                                        <div style="">
                                                            <?php
                                                                $ec_q1 = $Campaign_Functions->energy_chart_quarter($db,"q1");
                                                                $return = $Campaign_Functions->array_attributes($db,array("query"=>$query,"quarter"=>$ec_q1,"allow"=>true));
                                                            ?>
                                                            <table class="<?php echo $return['class']; ?>" data-status-type="<?php echo $return['status']; ?>" id="tbl_ec_q1" cellpadding="0" cellspacing="0" width="100%">
                                                                <thead>
                                                                    <tr>
                                                                        <th>
                                                                           Brand Story
                                                                        </th>
                                                                        <?php echo $Campaign_Functions->campaign_month('Quarter 1'); ?>
                                                                    </tr>
                                                                </thead>
                                                                <tbody class="<?php echo $return['allow_drag']; ?>" id="drag_ec_q1" style="width:100%;">
                                                                    <?php
                                                                        echo $Campaign_Functions->brand_story_table($data,"0","7","1","8","1","q1",$ec_q1,$return['array']);
                                                                    ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                            <div id="q-2">
                                                <?php
                                                        $sql = "SELECT * FROM " . $db->tbl_name(TB_CAMPAIGN_VERSION) .
                                                        " WHERE quarter = {$db->escape('q2')} ORDER BY campaign_id DESC";
                                                        $campaign_version_query = $db->query($sql,"array");
                                                        $campaign_version_query_nums = $db->query($sql,"numrows");
                                                        if($campaign_version_query_nums == 0){
                                                            echo '<p><strong><center>No Records Found.</center></strong></p>';
                                                        }
                                                    ?>
                                                <div class="accordion" style="overflow:auto">    
                                                    <?php
                                                        foreach($campaign_version_query as $data){
                                                    ?>
                                                        <h3><?php echo $data['version_name']; ?></h3>
                                                        <div style="">
                                                            <?php
                                                                $ec_q2 = $Campaign_Functions->energy_chart_quarter($db,"q2");
                                                                $return = $Campaign_Functions->array_attributes($db,array("query"=>$query,"quarter"=>$ec_q2,"allow"=>true));
                                                            ?>
                                                            <table class="<?php echo $return['class']; ?>" data-status-type="<?php echo $return['status']; ?>" id="tbl_ec_q2" cellpadding="0" cellspacing="0" width="100%">
                                                                <thead>
                                                                    <tr>
                                                                        <th>
                                                                           Brand Story
                                                                        </th>
                                                                        <?php echo $Campaign_Functions->campaign_month('Quarter 2'); ?>
                                                                    </tr>
                                                                </thead>
                                                                <tbody class="<?php echo $return['allow_drag']; ?>" id="drag_ec_q2" style="width:100%;">
                                                                    <?php
                                                                        echo $Campaign_Functions->brand_story_table($data,"0","7","7","14","7","q2",$ec_q2,$return['array']);
                                                                    ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                            <div id="q-3">
                                                    <?php
                                                        $sql = "SELECT * FROM " . $db->tbl_name(TB_CAMPAIGN_VERSION) .
                                                        " WHERE quarter = {$db->escape('q3')} ORDER BY campaign_id DESC";
                                                        $campaign_version_query = $db->query($sql,"array");
                                                        $campaign_version_query_nums = $db->query($sql,"numrows");
                                                        if($campaign_version_query_nums == 0){
                                                            echo '<p><strong><center>No Records Found.</center></strong></p>';
                                                        }
                                                    ?>
                                                <div class="accordion" style="overflow:auto">    
                                                    <?php
                                                        foreach($campaign_version_query as $data){
                                                    ?>
                                                        <h3><?php echo $data['version_name']; ?></h3>
                                                        <div style="">
                                                            <?php
                                                                $ec_q3 = $Campaign_Functions->energy_chart_quarter($db,"q3");
                                                                $return = $Campaign_Functions->array_attributes($db,array("query"=>$query,"quarter"=>$ec_q3,"allow"=>true));
                                                            ?>
                                                            <table class="<?php echo $return['class']; ?>" data-status-type="<?php echo $return['status']; ?>" id="tbl_ec_q3" cellpadding="0" cellspacing="0" width="100%">
                                                                <thead>
                                                                    <tr>
                                                                        <th>
                                                                           Brand Story
                                                                        </th>
                                                                        <?php echo $Campaign_Functions->campaign_month('Quarter 3'); ?>
                                                                    </tr>
                                                                </thead>
                                                                <tbody class="<?php echo $return['allow_drag']; ?>" id="drag_ec_q3" style="width:100%;">
                                                                    <?php
                                                                        echo $Campaign_Functions->brand_story_table($data,"0","7","13","20","13","q3",$ec_q3,$return['array']);
                                                                    ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                            <div id="q-4">
                                                    <?php
                                                        $sql = "SELECT * FROM " . $db->tbl_name(TB_CAMPAIGN_VERSION) .
                                                        " WHERE quarter = {$db->escape('q4')} ORDER BY campaign_id DESC";
                                                        $campaign_version_query = $db->query($sql,"array");
                                                        $campaign_version_query_nums = $db->query($sql,"numrows");
                                                        if($campaign_version_query_nums == 0){
                                                            echo '<p><strong><center>No Records Found.</center></strong></p>';
                                                        }
                                                    ?>
                                                <div class="accordion" style="overflow:auto">    
                                                    <?php
                                                        foreach($campaign_version_query as $data){
                                                    ?>
                                                        <h3><?php echo $data['version_name']; ?></h3>
                                                        <div style="">
                                                            <?php
                                                                $ec_q4 = $Campaign_Functions->energy_chart_quarter($db,"q4");
                                                                $return = $Campaign_Functions->array_attributes($db,array("query"=>$query,"quarter"=>$ec_q4,"allow"=>true));
                                                            ?>
                                                            <table class="<?php echo $return['class']; ?>" data-status-type="<?php echo $return['status']; ?>" id="tbl_ec_q4" cellpadding="0" cellspacing="0" width="100%">
                                                                <thead>
                                                                    <tr>
                                                                        <th>
                                                                           Brand Story
                                                                        </th>
                                                                        <?php echo $Campaign_Functions->campaign_month('Quarter 4'); ?>
                                                                    </tr>
                                                                </thead>
                                                                <tbody class="<?php echo $return['allow_drag']; ?>" id="drag_ec_q4" style="width:100%;">
                                                                    <?php
                                                                        echo $Campaign_Functions->brand_story_table($data,"0","7","19","26","19","q4",$ec_q4,$return['array']);
                                                                    ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                            <div id="view-all">
                                                    <?php
                                                        $sql = "SELECT * FROM " . $db->tbl_name(TB_CAMPAIGN_VERSION) .
                                                        " WHERE quarter = {$db->escape('all')} ORDER BY campaign_id DESC";
                                                        $campaign_version_query = $db->query($sql,"array");
                                                        $campaign_version_query_nums = $db->query($sql,"numrows");
                                                        if($campaign_version_query_nums == 0){
                                                            echo '<p><strong><center>No Records Found.</center></strong></p>';
                                                        }
                                                    ?>
                                                <div class="accordion" style="overflow:auto">    
                                                    <?php
                                                        foreach($campaign_version_query as $data){
                                                    ?>
                                                        <h3><?php echo $data['version_name']; ?></h3>
                                                        <div style="">
                                                            <?php
                                                                $ec_all = $Campaign_Functions->energy_chart_quarter($db,"all");
                                                                $return = $Campaign_Functions->array_attributes($db,array("query"=>$query,"quarter"=>$ec_all,"allow"=>true));
                                                            ?>
                                                            <table class="<?php echo $return['class']; ?>" data-status-type="<?php echo $return['status']; ?>" id="tbl_ec_q4" cellpadding="0" cellspacing="0" width="100%">
                                                                <thead>
                                                                    <tr>
                                                                        <th>
                                                                           Brand Story
                                                                        </th>
                                                                        <?php echo $Campaign_Functions->campaign_month('Full'); ?>
                                                                    </tr>
                                                                </thead>
                                                                <tbody class="<?php echo $return['allow_drag']; ?>" id="drag_ec_all" style="width:100%;">
                                                                    <?php
                                                                        echo $Campaign_Functions->brand_story_table($data,"0","7","1","26","1","all",$ec_all,$return['array']);
                                                                    ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                    </div>
                                
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>    
        </div>

   </div>

</div> 